package com.fxd.study.spring.ioc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author xudongfu
 * @date 2023/02/07
 */
@Slf4j
public class MyBean implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {

    public MyBean() {
        log.info("执行了无参数构造方法");
    }

    @Override
    public void setBeanName(String s) {
        log.info("开始执行 setBeanName 方法,参数: {}", s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        boolean exist = beanFactory.containsBean("myBean");
        log.info("开始执行 setBeanFactory 方法,myBean是否存在: {}", exist);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("开始执行 afterPropertiesSet 方法");
    }

    public void myInitMethod() {
        log.info("开始执行 myInitMethod 方法");
    }

    @Override
    public void destroy() throws Exception {
        log.info("开始执行 destroy 方法");
    }

    public void myDestroyMethod() {
        log.info("开始执行 myDestroyMethod 方法");
    }

}
